﻿using System;
namespace Demo4.LambdaDemo
{
    /// <summary>
    /// lambda表达式demo
    /// </summary>
    public class Main
    {
        private delegate void HelloWorld();
        private delegate void HelloCloud(int i);
        private delegate void PrintI();
        private Main()
        {
            HelloWorld h = () => Console.WriteLine("hello the world");
            HelloCloud hc = (int i) => Console.WriteLine($"{i} Hello the cloud");
            h();
            hc(1);
            //闭包
            const int capacity = 3;
            PrintI[] ps = new PrintI[capacity];
            for (int i = 0; i < 3; i++)
            {
                int temp = i;
                ps[i] = () => Console.WriteLine(temp);
            }

            for (int i = 0; i < capacity; i++)
            {
                ps[i]();
            }
        }
        
        public static Main NewInstance()
        {
            return new Main();

        }
    }
}